package com.hspedu.encap;

public class Account {
    private String name;
    private double balance;
    private  String pwd;

    //提供两个构造器
    public Account() {
    }

    public Account(String name, double balance, String pwd) {
        this.setName(name);
        this.setBalance(balance);
        this.setPwd(pwd);
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        if(name.length() >= 2 && name.length()<=4){
            this.name = name;
        }
        else{
            System.out.println("名字长度必须为(2-4)!!");
            this.name = "null";
        }
    }

    public double getBalance() {
        return balance;
    }

    //余额必须>20
    public void setBalance(double balance) {
        if(balance>20){
            this.balance = balance;
        }
        else{
            System.out.println("余额必须>20!");
        }
    }

    public String getPwd() {
        return pwd;
    }

    //密码必须是6为
    public void setPwd(String pwd) {
        if(pwd.length() == 6){
            this.pwd = pwd;
        }
        else {
            System.out.println("密码必须为6位!(默认为000000)");
            this.pwd = "000000";
        }
    }

    public void show(){
        System.out.println("名字->" + name + "余额->" + balance + "密码->" + pwd);
    }
}
